#pragma once

#include "snetwork/stdafx.h"
//#include "dameon.h"
#include "snetwork/snetwork.h"
#include "standard/DBConfig.h"
#include "standard/nhex.h"
#include "standard/dump.h"
#include "standard/CThrowException.h"

#define MAXLINE         10 
//#define OPEN_MAX        100 
#define LISTENQ         20 
#define INFTIM          1000 

#define SOCKLOPT_SERVER 2001
#define MAX_FD_NUM      200
#define WRAPCHAR        "\015\012"		//\r\n
#define OPEN_MYSQL      1

typedef struct retParamArra {
    int statu;
    std::string msg;
} retParamArr;

typedef struct paramArra {
    /** use to callaction*/
    vecStr *rbArr;
    mapStrStr *textinfo;
    mapStrStrIntStr *FILES;
    mapStrStr tGET;
    mapStrStr tPOST;
    void* cookie;

    /** use to class RequestSock */
	std::string module;
	vecStr fieldArr;
	std::string rootpath;
	void *dbconfig;
	
	/** use to class RecvSock */
    ssize_t *cnt_len;
    int sockfd;
    vecStr *sendArr;
    std::string method;
    std::string *action;
    int done;
    bool is_static;
    //unsigned int *thread_para;
    
    /** use to class SendSock */
    retParamArr retArr;        
    
    void* pobj;
    
    /*for master thread*/        
    void* tevent;  
    int epfd;
    unsigned int threadid;
    
    const char *dbname;
    
    /* statu */      
    bool is_run;
} paramArr;

typedef struct ParseGetParam {
    std::string *head_arr;
    std::string *action;
    mapStrStr *tget;
    mapStrStr *tpost;
} PGetParam;

namespace Sock
{
    class  SNETWORK_API CSockObject
    {
    public:
        virtual int execute(){return 0;}
    };
    	
	class CNluEvent;
	class CNluEventAccept;
	class CNluConnection;
	class CNluHttpRequest;
	class CNluHttpParse;
	class CNluHttpResponse;
	class CWorkerProcess;
	class CSendSock;
	class CContext;
	class CMasterThread;
	class CWorkerThread;	
	class CNluHttpCreate;	
	class CNluList;
	
	class  SNETWORK_API CSock
	{
	public:
		CSock();
		int nsock_init(unsigned int server_port);
		int nsock_setopt(int act, mapStrStr* param);
		int nsock_exec(vecStr& ret);
		int nsock_close();
    private:
        mapStrStr *m_param;		
	}; 

	//variable
	extern  int n_clientfd;
    extern  int n_fd_arr[MAX_FD_NUM];
    extern  char* n_clientip_arr[MAX_FD_NUM];
    extern  short int n_clientport_arr[MAX_FD_NUM];
    
    extern  int n_fd_count;
    extern  int n_serverfd;
    
    extern std::string n_response_header;
    extern std::string n_request_header;
    extern std::string n_response_body;
    extern vecStr n_rbArr;
    extern mapStrStr n_head_arr;
	extern std::string n_header;	
	extern mapStrStr n_fileinfo;
	extern mapStrStr n_textinfo;	
	extern mapStrStrIntStr n_FILES;
	
	extern int n_status;//http status
	
	//set cookie 
	extern mapStrStr n_CookieSend;//response
	extern mapStrStr n_CookieRecv;
	extern mapStrStr n_Cookie;//save
	
	//set session
	extern mapStrStr n_Session;//save
	
	//client ip
	extern std::string n_clientip;//client ip
};

typedef Sock::CSockObject* (*ClassCreateObject)(void*);
